<template>
  <div class="setting-shan-container">
    <div class="applet-blendent-header">设置点我达信息</div>
    <el-form :model="dianwodaData" label-width="170px" size="small" style="margin: 20px auto">
      <el-form-item label="appkey">
        <el-input v-model="dianwodaData.appkey" placeholder="请输入" style="width: 40%"/>
      </el-form-item>
      <el-form-item label="appsecret">
        <el-input v-model="dianwodaData.appsecret" placeholder="请输入" style="width: 40%"/>
      </el-form-item>
      <el-form-item label="accesstoken">
        <el-input v-model="dianwodaData.accesstoken" placeholder="请输入" style="width: 40%"/>
      </el-form-item>
    </el-form>

    <div style="text-align:center;margin-top:15px">
      <el-button type="primary" size="small" style="padding:8px 30px;" @click="submit">提 交</el-button>
    </div>
  </div>
</template>

<script>
import { getDianwoda, postDianwoda } from '@/api/setting'

export default {
  name: 'setting-shansong',
  data() {
    return {
      dianwodaData: { id: '', appkey: '', appsecret: '', accesstoken: '' },
    }
  },
  mounted() {
    this.getDianwoda();
  },
  methods: {
    getDianwoda() {
      getDianwoda({key: this.$store.state.app.activeApp.saa_key}).then(res => {
        if(res.status === 200) {
          this.dianwodaData.id = res.data.id;
          this.dianwodaData.appkey = res.data.appkey;
          this.dianwodaData.appsecret = res.data.appsecret;
          this.dianwodaData.accesstoken = res.data.accesstoken;
        }else{
          this.$message.error(res.message);
        }
      })
    },
    submit() {
      const params = {
        id: this.dianwodaData.id,
        key: this.$store.state.app.activeApp.saa_key,
        appkey: this.dianwodaData.appkey,
        appsecret: this.dianwodaData.appsecret,
        token: this.dianwodaData.accesstoken,
      };

      postDianwoda(params).then(res => {
        if(res.status === 200) {
          this.$message.success('修改成功！');
        }else{
          this.$message.error(res.message);
        }
      })
    }
  },
}
</script>

<style lang="scss" scoped>
.setting-shan-container{
  min-height: calc(100vh - 100px);
  margin: 20px;
  background-color: #fff;
  padding:25px;
  box-shadow: 0px 0px 4px 0px rgba(115, 115, 115, 0.2);
}
.applet-blendent-header{
  height: 40px;
  width: 100%;
  line-height: 40px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 2px;
  color: #8f8f8f;
  padding: 0 10px;
  background-color: #F4F8FB;
}
</style>
